class Solution {
public:
    string longestPalindrome(string s) {
        int n = s.size();
        vector<vector<bool>>f(n, vector<bool>(n));
        int len = 0, begin = 0;
        for (int i = n - 1; i >= 0; i--) {
            for (int j = i; j < n; j++) {
                if (s[i] != s[j])continue;
                if (i + 1 == j || i == j)f[i][j] = 1;
                if (i + 1 < j)f[i][j] = f[i + 1][j - 1];
                if (f[i][j]) {
                    if (j - i + 1 > len) {
                        len = j - i + 1;
                        begin = i;
                    }
                }
            }
        }
        cout << "len==" << len << endl;
        return s.substr(begin, len);
    }
};